package com.xbongbong.paas.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.pojo.dto.AttrTrashDeleteDTO;
import com.xbongbong.paas.pojo.dto.AttrTrashListDTO;
import com.xbongbong.paas.pojo.dto.AttrTrashRecoverDTO;
import com.xbongbong.paas.pojo.dto.BusinessRuleWhiteDTO;
import com.xbongbong.paas.pojo.dto.CoUserPermissionListDTO;
import com.xbongbong.paas.pojo.dto.CoUserPermissionUpdateDTO;
import com.xbongbong.paas.pojo.dto.ComboLinkExplainListDTO;
import com.xbongbong.paas.pojo.dto.CustomRepeatLinkExplainDTO;
import com.xbongbong.paas.pojo.dto.FieldTypeListDTO;
import com.xbongbong.paas.pojo.dto.FormAllListDTO;
import com.xbongbong.paas.pojo.dto.FormDecisionInfoUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormGetDTO;
import com.xbongbong.paas.pojo.dto.FormListDTO;
import com.xbongbong.paas.pojo.dto.FormRoleDetailDTO;
import com.xbongbong.paas.pojo.dto.FormRoleUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormTitleListDTO;
import com.xbongbong.paas.pojo.dto.FormUpdateDTO;
import com.xbongbong.paas.pojo.dto.MenuFormCopyDTO;
import com.xbongbong.paas.pojo.dto.UpdateExplainStageDTO;
import com.xbongbong.paas.pojo.dto.UserApproveListDTO;
import com.xbongbong.paas.pojo.vo.AttrTrashDeleteVO;
import com.xbongbong.paas.pojo.vo.AttrTrashListVO;
import com.xbongbong.paas.pojo.vo.BusinessRuleWhiteVO;
import com.xbongbong.paas.pojo.vo.CoUserPermissionListVO;
import com.xbongbong.paas.pojo.vo.CoUserPermissionUpdateVO;
import com.xbongbong.paas.pojo.vo.ComboLinkExplainListVO;
import com.xbongbong.paas.pojo.vo.FieldTypeListVO;
import com.xbongbong.paas.pojo.vo.FormAllListVO;
import com.xbongbong.paas.pojo.vo.FormDecisionInfoGetVO;
import com.xbongbong.paas.pojo.vo.FormGetVO;
import com.xbongbong.paas.pojo.vo.FormListVO;
import com.xbongbong.paas.pojo.vo.FormRoleDetailVO;
import com.xbongbong.paas.pojo.vo.FormRoleUpdateVO;
import com.xbongbong.paas.pojo.vo.FormTitleListVO;
import com.xbongbong.paas.pojo.vo.FormUpdateVO;
import com.xbongbong.paas.pojo.vo.MenuFormCopyVO;
import com.xbongbong.paas.pojo.vo.MenuListVO;
import com.xbongbong.paas.pojo.vo.UserApproveListVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.service.ClueJointRecheckService;
import com.xbongbong.paas.service.PaasFormService;
import com.xbongbong.paas.service.ResultShowRuleService;
import com.xbongbong.paas.service.impl.PaasFormAttrTrashServiceImpl;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.businesstage.pojo.dto.RuleEnableDTO;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.form.pojo.dto.AllAppFormListDTO;
import com.xbongbong.pro.form.pojo.dto.AppFormListDTO;
import com.xbongbong.pro.form.pojo.dto.BusinessFieldDTO;
import com.xbongbong.pro.form.pojo.dto.ClueConvertRuleSaveDTO;
import com.xbongbong.pro.form.pojo.dto.ClueConvertRulesListSaveDTO;
import com.xbongbong.pro.form.pojo.dto.ClueJointRecheckCustomerAttrDTO;
import com.xbongbong.pro.form.pojo.dto.EnableAssociationListDTO;
import com.xbongbong.pro.form.pojo.dto.FieldConvertRuleDTO;
import com.xbongbong.pro.form.pojo.dto.FormAssociationListDTO;
import com.xbongbong.pro.form.pojo.dto.FormBusinessRuleDTO;
import com.xbongbong.pro.form.pojo.dto.FormClueJointRecheckDTO;
import com.xbongbong.pro.form.pojo.dto.FormClueJointRecheckSaveDTO;
import com.xbongbong.pro.form.pojo.dto.FormDeleteDTO;
import com.xbongbong.pro.form.pojo.dto.FormResultRuleSaveDTO;
import com.xbongbong.pro.form.pojo.dto.FormResultShowRuleDTO;
import com.xbongbong.pro.form.pojo.dto.FormRuleListDTO;
import com.xbongbong.pro.form.pojo.dto.FormUpdateBusinessRuleDTO;
import com.xbongbong.pro.form.pojo.dto.FormUpdateNameDTO;
import com.xbongbong.pro.form.pojo.dto.HomePageDeleteDTO;
import com.xbongbong.pro.form.pojo.dto.HomePageUpdateDTO;
import com.xbongbong.pro.form.pojo.vo.AllAppFormListVO;
import com.xbongbong.pro.form.pojo.vo.BusinessFieldVO;
import com.xbongbong.pro.form.pojo.vo.ClueConvertRuleVO;
import com.xbongbong.pro.form.pojo.vo.ClueJointRecheckCustomerAttrVO;
import com.xbongbong.pro.form.pojo.vo.CustomRepeatLinkExplainGetVO;
import com.xbongbong.pro.form.pojo.vo.EnableAssociationListVO;
import com.xbongbong.pro.form.pojo.vo.FieldConvertRuleVO;
import com.xbongbong.pro.form.pojo.vo.FormAssociationListVO;
import com.xbongbong.pro.form.pojo.vo.FormBusinessRuleVO;
import com.xbongbong.pro.form.pojo.vo.FormClueJointRecheckAllRuleVO;
import com.xbongbong.pro.form.pojo.vo.FormClueJointRecheckVO;
import com.xbongbong.pro.form.pojo.vo.FormDeleteVO;
import com.xbongbong.pro.form.pojo.vo.FormResultShowRuleVO;
import com.xbongbong.pro.form.pojo.vo.FormRuleListVO;
import com.xbongbong.pro.form.pojo.vo.FormUpdateBusinessRuleVO;
import com.xbongbong.pro.form.pojo.vo.FormUpdateNameVO;
import com.xbongbong.pro.form.pojo.vo.HomePageListVO;
import com.xbongbong.pro.form.pojo.vo.SupportLinkageFieldsVO;
import com.xbongbong.pro.form.pojo.vo.UpdateExplainStageVO;
import com.xbongbong.pro.menu.pojo.dto.QuickNewListDTO;
import com.xbongbong.pro.menu.pojo.vo.QuickNewListVO;
import com.xbongbong.pro.recheck.pojo.dto.RecheckingRuleGetDTO;
import com.xbongbong.pro.recheck.pojo.dto.RecheckingRuleSaveDTO;
import com.xbongbong.pro.recheck.pojo.vo.RecheckingAttrListVO;
import com.xbongbong.pro.recheck.pojo.vo.RecheckingFieldListVO;
import com.xbongbong.pro.recheck.pojo.vo.RecheckingRuleListVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.service.RecheckingRuleService;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/8/13 17:24
 * @desrcption: 表单操作
 */
@RestController
@RequestMapping(value = XbbProConstant.API_ROOT_PREFIX + "/form")
public class PaasFormController {


    @Resource
    private PaasFormService paasFormService;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private PaasFormAttrTrashServiceImpl paasFormAttrTrashServiceImpl;
    @Resource
    private ResultShowRuleService resultShowRuleService;
    @Resource
    private ClueJointRecheckService clueJointRecheckService;
    @Resource
    private RecheckingRuleService recheckingRuleService;

    /**
     * 检索当前应用的表单或者流程表单
     * @param formListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String formList(@RequestBody @Valid FormListDTO formListDTO, BindingResult br){
        XbbResponse<FormListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormListVO formListVO = paasFormService.formList(formListDTO);
                response = new XbbResponse<>(formListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 日志检索当前应用启用的菜单
     * @param formListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/log/menuList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String logMenuList(@RequestBody @Valid FormListDTO formListDTO, BindingResult br){
        XbbResponse<MenuListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                MenuListVO menuListVO = paasFormService.logMenuList(formListDTO);
                response = new XbbResponse<>(menuListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }



    /**
     * 检索所有应用的表单或者流程表单
     * @param formAllListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/allList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAllformList(@RequestBody @Valid FormAllListDTO formAllListDTO, BindingResult br){
        XbbResponse<FormAllListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormAllListVO allformList = paasFormService.getAllformList(formAllListDTO);
                response = new XbbResponse<>(allformList);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 检索所有应用的表单或者流程表单 不包含 工作报告
     * @param allAppFormListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/app/allList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAllAppFormList(@RequestBody @Valid AllAppFormListDTO allAppFormListDTO, BindingResult br){
        XbbResponse<AllAppFormListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                AllAppFormListVO allAppFormListVO = paasFormService.getAllAppFormList(allAppFormListDTO);
                response = new XbbResponse<>(allAppFormListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 检索所有应用的表单或者流程表单 包含 工作报告
     * @param appFormListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/appFormList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAppFormList(@RequestBody @Valid AppFormListDTO appFormListDTO, BindingResult br){
        XbbResponse<AllAppFormListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                AllAppFormListVO allAppFormListVO = paasFormService.getAppFormList(appFormListDTO);
                response = new XbbResponse<>(allAppFormListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 所有应用的表单和字段列表
     * @param comboLinkExplainListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/combo/link/explain", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String comboLinkExplain(@RequestBody @Valid ComboLinkExplainListDTO comboLinkExplainListDTO, BindingResult br){
        XbbResponse<ComboLinkExplainListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ComboLinkExplainListVO comboLinkExplainListVO = paasFormService.comboLinkExplainList(comboLinkExplainListDTO);
                response = new XbbResponse<>(comboLinkExplainListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 检索表单的相应属性信息
     * @param formGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String get(@RequestBody @Valid FormGetDTO formGetDTO, BindingResult br){
        XbbResponse<FormGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormGetVO formGetVO = paasFormService.get(formGetDTO);
                response = new XbbResponse<>(formGetVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存表单设计阶段的数据
     * @param formUpdateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String save(@RequestBody @Valid FormUpdateDTO formUpdateDTO, BindingResult br){
        XbbResponse<FormUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // ----------------------------------repeat post----------------------------------------------
            // 判断是否跳过重复提交校验
            if (!Boolean.TRUE.equals(formUpdateDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(formUpdateDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            // ----------------------------------repeat post----------------------------------------------
            try {
                FormUpdateVO formUpdateVO = paasFormService.update(formUpdateDTO);
                response = new XbbResponse<>(formUpdateVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        // 释放并发锁, 做3秒的限制
//        paasRedisHelper.releaseConcurrentLock(formUpdateDTO);
        return JSON.toJSONString(response);
    }

    /**
     * 表单复制接口
     * @param menuFormCopyDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/copy", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String copy(@RequestBody @Valid MenuFormCopyDTO menuFormCopyDTO, BindingResult br){
        XbbResponse<MenuFormCopyVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // ----------------------------------repeat post----------------------------------------------
            // 判断是否跳过重复提交校验
            if (!Boolean.TRUE.equals(menuFormCopyDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(menuFormCopyDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            // ----------------------------------repeat post----------------------------------------------
            try {
                MenuFormCopyVO menuFormCopyVO = paasFormService.copy(menuFormCopyDTO);
                response = new XbbResponse<>(menuFormCopyVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    @RequestMapping(value = "/updateName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateName(@RequestBody @Valid FormUpdateNameDTO formUpdateNameDTO, BindingResult br){
        XbbResponse<FormUpdateNameVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormUpdateNameVO formUpdateNameVO = paasFormService.updateName(formUpdateNameDTO);
                response = new XbbResponse<>(formUpdateNameVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 查看标签字段列表
     * @param fieldTypeListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fieldType/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fieldTypeList(@RequestBody @Valid FieldTypeListDTO fieldTypeListDTO, BindingResult br){
        XbbResponse<FieldTypeListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FieldTypeListVO fieldTypeList = paasFormService.fieldTypeList(fieldTypeListDTO);
                response = new XbbResponse<>(fieldTypeList);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 协同人权限获取
     * @param synergeticListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/synergetic/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String synergeticList(@RequestBody @Valid CoUserPermissionListDTO synergeticListDTO, BindingResult br){
        XbbResponse<CoUserPermissionListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CoUserPermissionListVO synergeticListVO = paasFormService.synergeticList(synergeticListDTO);
                response = new XbbResponse<>(synergeticListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 协同人权限设置
     * @param synergeticUpdateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/synergetic/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String synergeticUpdate(@RequestBody @Valid CoUserPermissionUpdateDTO synergeticUpdateDTO, BindingResult br){
        XbbResponse<CoUserPermissionUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CoUserPermissionUpdateVO synergeticListVO = paasFormService.synergeticUpdate(synergeticUpdateDTO);
                response = new XbbResponse<>(synergeticListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 检索用户的审批表单
     * @param userApproveListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/userApprove/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String userApproveList(@RequestBody @Valid UserApproveListDTO userApproveListDTO, BindingResult br){
        XbbResponse<UserApproveListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                UserApproveListVO userApproveListVO = paasFormService.userApproveList(userApproveListDTO);
                response = new XbbResponse<>(userApproveListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取标题列表
     * @param formTitleListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/title/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String titleList(@RequestBody @Valid FormTitleListDTO formTitleListDTO, BindingResult br){
        XbbResponse<FormTitleListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormTitleListVO formTitleListVO = paasFormService.titleList(formTitleListDTO);
                response = new XbbResponse<>(formTitleListVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 表单设计 -> 表单设置 获取角色对应的该表单的权限信息
     * @param roleDetailDTO 业务DTO
     * @param br 参数验证器
     */
    @RequestMapping(value = "/roleDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String roleDetail(@RequestBody @Valid FormRoleDetailDTO roleDetailDTO, BindingResult br){
        XbbResponse<FormRoleDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormRoleDetailVO roleDetailVO = paasFormService.roleDetail(roleDetailDTO);
                response = new XbbResponse<>(roleDetailVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 表单设计 -> 表单设置 设置角色对应的该表单的权限信息
     * @param roleUpdateDTO 业务DTO
     * @param br 参数验证器
     */
    @RequestMapping(value = "/roleUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String roleUpdate(@RequestBody @Valid FormRoleUpdateDTO roleUpdateDTO, BindingResult br){
        XbbResponse<FormRoleUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormRoleUpdateVO roleUpdateVO = paasFormService.roleUpdate(roleUpdateDTO);
                response = new XbbResponse<>(roleUpdateVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    @RequestMapping(value = "/quickNewList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String query(@RequestBody @Valid QuickNewListDTO quickNewListDTO, BindingResult br) throws Exception{
        XbbResponse<QuickNewListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                QuickNewListVO quickNewListVO = paasFormService.quickNewList(quickNewListDTO);
                response = new XbbResponse<>(quickNewListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 删除表单
     * @param formDeleteDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delete(@RequestBody @Valid FormDeleteDTO formDeleteDTO, BindingResult br) throws Exception{
        XbbResponse<FormDeleteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDeleteVO formDeleteVO = paasFormService.delete(formDeleteDTO);
                response = new XbbResponse<>(formDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 关联列表
     * @param formAssociationListDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/associationList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String association(@RequestBody @Valid FormAssociationListDTO formAssociationListDTO, BindingResult br) throws Exception{
        XbbResponse<FormAssociationListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormAssociationListVO formAssociationListVO = paasFormService.associationList(formAssociationListDTO);
                response = new XbbResponse<>(formAssociationListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 启用关联列表
     * @param enableAssociationListDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/enableAssociation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enableAssociation(@RequestBody @Valid EnableAssociationListDTO enableAssociationListDTO, BindingResult br) throws Exception{
        XbbResponse<EnableAssociationListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                EnableAssociationListVO enableAssociationListVO = paasFormService.enableAssociation(enableAssociationListDTO);
                response = new XbbResponse<>(enableAssociationListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 更新规则的启用接口
     * @param ruleEnableDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/enableChangeTime", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enableChangeTime(@RequestBody @Valid RuleEnableDTO ruleEnableDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = paasFormService.enableChangeTime(ruleEnableDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 校验版本以及白名单
     * @param businessRuleWhiteDTO
     * @param br
     * @return
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/validateVersionAndWhite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String validateVersionAndWhite(@RequestBody @Valid BusinessRuleWhiteDTO businessRuleWhiteDTO, BindingResult br) {
        XbbResponse<BusinessRuleWhiteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BusinessRuleWhiteVO businessRuleWhiteVO = paasFormService.validateVersionAndWhite(businessRuleWhiteDTO);
                response = new XbbResponse<>(businessRuleWhiteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 更新业务
     * http://yapi.xbongbong.com/project/87/interface/api/12753
     * @param formUpdateBusinessRuleDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateBusinessRule", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateBusinessRule(@RequestBody @Valid FormUpdateBusinessRuleDTO formUpdateBusinessRuleDTO, BindingResult br) throws Exception{
        XbbResponse<FormUpdateBusinessRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormUpdateBusinessRuleVO formUpdateBusinessRuleVO = paasFormService.updateBusinessRule(formUpdateBusinessRuleDTO);
                response = new XbbResponse<>(formUpdateBusinessRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 业务规则获取
     * http://yapi.xbongbong.com/project/87/interface/api/12758
     * @param formBusinessRuleDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/businessRuleList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String businessRuleList(@RequestBody @Valid FormBusinessRuleDTO formBusinessRuleDTO, BindingResult br) throws Exception{
        XbbResponse<FormBusinessRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormBusinessRuleVO formBusinessRuleVO = paasFormService.businessRuleList(formBusinessRuleDTO);
                response = new XbbResponse<>(formBusinessRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 结果展示规则获取
     * @param formResultShowRuleDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/result/show/ruleList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String resultShowRuleList(@RequestBody @Valid FormResultShowRuleDTO formResultShowRuleDTO, BindingResult br) throws Exception{
        XbbResponse<FormResultShowRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormResultShowRuleVO formResultShowRuleVO = resultShowRuleService.get(formResultShowRuleDTO);
                response = new XbbResponse<>(formResultShowRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }



    /**
     * 更新结果展示规则
     * @param formResultRuleSaveDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/result/show/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String resultShowRuleList(@RequestBody @Valid FormResultRuleSaveDTO formResultRuleSaveDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // 判断是否跳过重复提交校验
            if (!Boolean.TRUE.equals(formResultRuleSaveDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(formResultRuleSaveDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            try {
                BaseVO save = resultShowRuleService.save(formResultRuleSaveDTO);
                response = new XbbResponse<>(save);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * @description 重复规则的List接口
     * @author yanglei
     * @date 2022/11/9 9:40
     * @param recheckingRuleGetDTO
     * @param br
     * @return String
     */
    @RequestMapping(value = "/rechecking/rule/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String recheckingRuleGet(@RequestBody @Valid RecheckingRuleGetDTO recheckingRuleGetDTO, BindingResult br) throws Exception{
        XbbResponse<RecheckingRuleListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RecheckingRuleListVO recheckingRuleListVO = recheckingRuleService.getList(recheckingRuleGetDTO);
                response = new XbbResponse<>(recheckingRuleListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/rechecking/attrAndForm/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String recheckingAttrGet(@RequestBody @Valid RecheckingRuleGetDTO recheckingRuleGetDTO, BindingResult br) throws Exception{
        XbbResponse<RecheckingFieldListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RecheckingFieldListVO recheckingFieldListVO = recheckingRuleService.getRecheckAttrAndFormList(recheckingRuleGetDTO);
                response = new XbbResponse<>(recheckingFieldListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/rechecking/attrByForm/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String recheckingAttrGetByForm(@RequestBody @Valid RecheckingRuleGetDTO recheckingRuleGetDTO, BindingResult br) throws Exception{
        XbbResponse<RecheckingAttrListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                recheckingRuleGetDTO.setOperateFlag(BasicConstant.ZERO);
                RecheckingAttrListVO attrListVO = recheckingRuleService.getRecheckAttrByForm(recheckingRuleGetDTO);
                response = new XbbResponse<>(attrListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/rechecking/rule/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String recheckingRuleSave(@RequestBody @Valid RecheckingRuleSaveDTO saveDTO, BindingResult br) throws Exception{
        XbbResponse<Integer> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                response = new XbbResponse<>(recheckingRuleService.save(saveDTO));
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取首页列表（仪表盘/CRM首页）
     * @param baseDTO 入参
     * @param br 校验信息
     * @return JSON
     * @throws Exception error
     * @author zhouwq
     * @date 2020/9/2 10:13
     */
    @RequestMapping(value = "/homePageList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String homePageList(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) throws Exception{
        XbbResponse<HomePageListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                HomePageListVO homePageListVO = paasFormService.homePageList(baseDTO);
                response = new XbbResponse<>(homePageListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 首页列表配置信息更新
     * @param homePageUpdateDTO 入参
     * @param br 校验信息
     * @return json
     * @throws Exception error
     * @author zhouwq
     * @date 2020/9/2 11:08
     */
    @RequestMapping(value = "/homePageUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String homePageUpdate(@RequestBody @Valid HomePageUpdateDTO homePageUpdateDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            if (!Boolean.TRUE.equals(homePageUpdateDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(homePageUpdateDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            try {
                BaseVO baseVO = paasFormService.homePageUpdate(homePageUpdateDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 首页列表配置信息更新
     * @param homePageDeleteDTO 入参
     * @param br 校验信息
     * @return json
     * @throws Exception error
     * @author zhouwq
     * @date 2020/9/2 11:08
     */
    @RequestMapping(value = "/homePageDelete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public String homePageDelete(@RequestBody @Valid HomePageDeleteDTO homePageDeleteDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            if (!Boolean.TRUE.equals(homePageDeleteDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(homePageDeleteDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            try {
                BaseVO baseVO = paasFormService.homePageDelete(homePageDeleteDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 关联“设置更新规则”列表
     * @param formRuleListDTO
     * http://yapi.xbongbong.com/project/87/interface/api/17194
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getRuleList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getRuleList(@RequestBody @Valid FormRuleListDTO formRuleListDTO, BindingResult br) throws Exception{
        XbbResponse<FormRuleListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormRuleListVO formRuleListVO = paasFormService.getRuleList(formRuleListDTO);
                response = new XbbResponse<>(formRuleListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     *
     * 根据套餐删除表单
     * @param formDeleteDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteByPackage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String deleteByPackage(@RequestBody @Valid FormDeleteDTO formDeleteDTO, BindingResult br) throws Exception{
        XbbResponse<FormDeleteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDeleteVO formDeleteVO = paasFormService.deleteByPackage(formDeleteDTO);
                response = new XbbResponse<>(formDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }



    /**
     * 获取工商查询匹配的所有字段
     * @param businessFieldDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/business/fieldList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String businessFieldList(@RequestBody @Valid BusinessFieldDTO businessFieldDTO, BindingResult br) throws Exception{
        XbbResponse<BusinessFieldVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BusinessFieldVO businessFieldVO = paasFormService.businessFieldList(businessFieldDTO);
                response = new XbbResponse<>(businessFieldVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * @Author mingliang
     * @Description 获得精线索查询字段
     * @Date 2021/10/27 15:40
     * @param businessFieldDTO
     * @param br
     **/
    @RequestMapping(value = "/fineClue/fieldList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fineClueFieldList(@RequestBody @Valid BusinessFieldDTO businessFieldDTO, BindingResult br) throws Exception{
        XbbResponse<BusinessFieldVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BusinessFieldVO businessFieldVO = paasFormService.fineClueFieldList(businessFieldDTO);
                response = new XbbResponse<>(businessFieldVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取线索转换客户规则
     * @param clueConvertRuleSaveDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/clue/convert/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueConverGet(@RequestBody @Valid ClueConvertRuleSaveDTO clueConvertRuleSaveDTO, BindingResult br) throws Exception{
        XbbResponse<ClueConvertRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ClueConvertRuleVO clueConvertRuleVO = paasFormService.getClueConvertRule(clueConvertRuleSaveDTO);
                response = new XbbResponse<>(clueConvertRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取线索转换客户规则
     * @param clueConvertRuleSaveDTO
     * @param br
     * @return
     * @throws Exception
     */
    /*@RequestMapping(value = "/clue/convert/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueConverSave(@RequestBody @Valid ClueConvertRuleSaveDTO clueConvertRuleSaveDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = paasFormService.clueConverSave(clueConvertRuleSaveDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }*/
    /**
     * 获取线索转换客户规则
     * @param clueConvertRulesListSaveDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/clue/convert/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueConverSave(@RequestBody @Valid ClueConvertRulesListSaveDTO clueConvertRulesListSaveDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = paasFormService.clueConverRulesListSave(clueConvertRulesListSaveDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取支持数据联动的字段类型
     * @param clueConvertRuleSaveDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/support/linkage/fields", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String supportLinkageFields(@RequestBody @Valid ClueConvertRuleSaveDTO clueConvertRuleSaveDTO, BindingResult br) throws Exception{
        XbbResponse<SupportLinkageFieldsVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SupportLinkageFieldsVO supportLinkageFieldsVO = paasFormService.supportLinkageFields(clueConvertRuleSaveDTO);
                response = new XbbResponse<>(supportLinkageFieldsVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取字段映射规则
     * @param fieldConvertRuleDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/field/convert/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fieldConvertGet(@RequestBody @Valid FieldConvertRuleDTO fieldConvertRuleDTO, BindingResult br) throws Exception{
        XbbResponse<FieldConvertRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FieldConvertRuleVO fieldConvertRuleVO = paasFormService.getFieldConvertRule(fieldConvertRuleDTO);
                response = new XbbResponse<>(fieldConvertRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存字段映射规则
     * @param fieldConvertRuleDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/field/convert/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueConverSave(@RequestBody @Valid FieldConvertRuleDTO fieldConvertRuleDTO, BindingResult br) throws Exception{
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = paasFormService.fieldConvertSave(fieldConvertRuleDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/trash/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String trashList(@RequestBody @Valid AttrTrashListDTO attrTrashListDTO, BindingResult br) throws Exception {
        XbbResponse<AttrTrashListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                AttrTrashListVO attrTrashListVO = paasFormAttrTrashServiceImpl.trashList(attrTrashListDTO);
                response = new XbbResponse<>(attrTrashListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/trash/recover", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String trashRecover(@RequestBody @Valid AttrTrashRecoverDTO attrTrashRecoverDTO, BindingResult br) throws Exception {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = paasFormAttrTrashServiceImpl.trashRecover(attrTrashRecoverDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/trash/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String trashRecover(@RequestBody @Valid AttrTrashDeleteDTO attrTrashDeleteDTO, BindingResult br) throws Exception {
        XbbResponse<AttrTrashDeleteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                AttrTrashDeleteVO attrTrashDeleteVO = paasFormAttrTrashServiceImpl.trashDelete(attrTrashDeleteDTO);
                response = new XbbResponse<>(attrTrashDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 设置阶段流程后返回表单设计页返回当前启用流程的阶段信息
     * @param updateExplainStageDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/enableProcess/stages/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateExplainStage(@RequestBody @Valid UpdateExplainStageDTO updateExplainStageDTO, BindingResult br) throws Exception{
        XbbResponse<UpdateExplainStageVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                UpdateExplainStageVO updateExplainStageVO = paasFormService.updateExplainStage(updateExplainStageDTO);
                response = new XbbResponse<>(updateExplainStageVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 获取查重关联字段
     * @param customRepeatLinkExplainDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customRepeat/link/explain", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customRepeatLinkExplain(@RequestBody @Valid CustomRepeatLinkExplainDTO customRepeatLinkExplainDTO, BindingResult br){
        XbbResponse<CustomRepeatLinkExplainGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CustomRepeatLinkExplainGetVO customRepeatLinkExplainGetVO = paasFormService.customRepeatLinkExplain(customRepeatLinkExplainDTO);
                response = new XbbResponse<>(customRepeatLinkExplainGetVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /***
     * 获取项目决策信息表单
     *
     * @param formGetDTO
     * @param: br
     * @throws
     * @return java.lang.String
     * @author hongxiao
     * @date 2021-11-19 14:32
     * @since
     * @version
     */
    @RequestMapping(value = "/decisionInfo/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String decisionInfoGet(@RequestBody @Valid FormGetDTO formGetDTO, BindingResult br){
        XbbResponse<FormDecisionInfoGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDecisionInfoGetVO formDecisionInfoGetVO = paasFormService.decisionInfoGet(formGetDTO);
                response = new XbbResponse<>(formDecisionInfoGetVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /***
     * 保存项目决策信息表单
     *
     * @param decisionInfoUpdateDTO
     * @param: br
     * @throws
     * @return java.lang.String
     * @author hongxiao
     * @date 2021-11-19 14:33
     * @since
     * @version
     */
    @RequestMapping(value = "/decisionInfo/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String decisionInfoSave(@RequestBody @Valid FormDecisionInfoUpdateDTO decisionInfoUpdateDTO, BindingResult br) throws XbbException {
        XbbResponse<FormUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // ----------------------------------repeat post----------------------------------------------
            // 判断是否跳过重复提交校验
            if (!Boolean.TRUE.equals(decisionInfoUpdateDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(decisionInfoUpdateDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            // ----------------------------------repeat post----------------------------------------------
            try {
                FormUpdateVO formUpdateVO = paasFormService.decisionInfoUpdate(decisionInfoUpdateDTO);
                response = new XbbResponse<>(formUpdateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
}
